package com.ruoyi.TraditionalCultureSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.TraditionalCultureSys.domain.RedRelics;
import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.TraditionalCultureSys.domain.TraditionalCultures;
import com.ruoyi.TraditionalCultureSys.service.ITraditionalCulturesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 传统文化Controller
 * 
 * @author ruoyi
 * @date 2024-06-24
 */
@RestController
@RequestMapping("/TraditionalCultureSys/cultures")
public class TraditionalCulturesController extends BaseController
{
    @Autowired
    private ITraditionalCulturesService traditionalCulturesService;

    /**
     * 查询传统文化列表
     */
    @PreAuthorize("@ss.hasPermi('list')")
    @GetMapping("/list")
    public TableDataInfo list(TraditionalCultures traditionalCultures)
    {
        startPage();
        List<TraditionalCultures> list = traditionalCulturesService.selectTraditionalCulturesList(traditionalCultures);
        return getDataTable(list);
    }

    /**
     * 导出传统文化列表
     */
    @PreAuthorize("@ss.hasPermi('export')")
    @Log(title = "传统文化", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TraditionalCultures traditionalCultures)
    {
        List<TraditionalCultures> list = traditionalCulturesService.selectTraditionalCulturesList(traditionalCultures);
        ExcelUtil<TraditionalCultures> util = new ExcelUtil<TraditionalCultures>(TraditionalCultures.class);
        util.exportExcel(response, list, "传统文化数据");
    }

    /**
     * 获取传统文化详细信息
     */
    @PreAuthorize("@ss.hasPermi('query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(traditionalCulturesService.selectTraditionalCulturesById(id));
    }

    /**
     * 新增传统文化
     */
    @PreAuthorize("@ss.hasPermi('add')")
    @Log(title = "传统文化", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TraditionalCultures traditionalCultures)
    {
        return toAjax(traditionalCulturesService.insertTraditionalCultures(traditionalCultures));
    }

    /**
     * 修改传统文化
     */
    @PreAuthorize("@ss.hasPermi('edit')")
    @Log(title = "传统文化", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TraditionalCultures traditionalCultures)
    {
        return toAjax(traditionalCulturesService.updateTraditionalCultures(traditionalCultures));
    }

    /**
     * 删除传统文化
     */
    @PreAuthorize("@ss.hasPermi('remove')")
    @Log(title = "传统文化", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(traditionalCulturesService.deleteTraditionalCulturesByIds(ids));
    }

    /**
     *
     * @return 全部传统文化信息
     */
    @Anonymous
    @ResponseBody
    @RequestMapping(value = "/getAllTraditionalCultures", produces = {"application/json;charset=utf-8"})
    public AjaxResult getAllTraditionalCultures() {
        List<TraditionalCultures> traditionalCultures = traditionalCulturesService.getAllTraditionalCultures();
        return AjaxResult.success("traditionalCultures",traditionalCultures);
    }
}
